/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.ipti.br.tag.util.CalendarUtil;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Entity
@DiscriminatorValue("J")
public class Juridic extends Person implements Serializable {

    @Column(nullable=false, name="company_name", length=60)
    private String companyName;
    
    @Column(nullable=false, name="fancy_name", length=60)
    private String fancyName;
    
    public Juridic() {
        super();
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String juridicHashString = "" + this.getCompanyName() + this.getFancyName()
                    + ((this.getAddress() != null) ? this.getAddress().getId() : null)
                    + ((this.getBirthday() != null) ? CalendarUtil.getFormatedDate(this.getBirthday()) : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(juridicHashString).hashCode()));
        }
    }

    public Juridic(String companyName, String fancyName, String email, String phone, String celphone, Address address, Calendar birthday, Nationality nationality) {
        super(email, phone, celphone, address, birthday, nationality);
        this.companyName = companyName;
        this.fancyName = fancyName;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getFancyName() {
        return fancyName;
    }

    public void setFancyName(String fancyName) {
        this.fancyName = fancyName;
    }
    
}
